package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.common.lib.fragment.BaseFragment;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.thinkfit.jy.R;

/**
 * 选择屏保时间界面
 */
public class SelectScreenProtectTimeFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {
    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
//        return DataManager.Companion.getInstance().getMainStyle() == 3 ? R.layout.fragment_select_screen_protect_time_xm :
        return  R.layout.fragment_select_screen_protect_time;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        setViewsOnClickListener(R.id.tvBack, R.id.llTime0, R.id.llTime1, R.id.llTime2, R.id.llTime3
                , R.id.llTime4, R.id.llTime5);
        resetTimeUI(DataManager.Companion.getInstance().getScreenTime());
    }

    private void resetTimeUI(int current) {
        for (int i = 0; i < 6; ++i) {
            ViewGroup llTime = getView().findViewById(
                    getResources().getIdentifier("llTime" + i, "id", getActivity().getPackageName())
            );
            llTime.getChildAt(1).setVisibility(current == i ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvBack:
                getParentFragmentManager().popBackStack();
                break;
            case R.id.llTime0:
                DataManager.Companion.getInstance().saveScreenTime(0);
                resetTimeUI(0);
                break;
            case R.id.llTime1:
                DataManager.Companion.getInstance().saveScreenTime(1);
                resetTimeUI(1);
                break;
            case R.id.llTime2:
                DataManager.Companion.getInstance().saveScreenTime(2);
                resetTimeUI(2);
                break;
            case R.id.llTime3:
                DataManager.Companion.getInstance().saveScreenTime(3);
                resetTimeUI(3);
                break;
            case R.id.llTime4:
                DataManager.Companion.getInstance().saveScreenTime(4);
                resetTimeUI(4);
                break;
            case R.id.llTime5:
                DataManager.Companion.getInstance().saveScreenTime(5);
                resetTimeUI(5);
                break;
        }
    }
}
